﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CtrLayer;
using ModelLayer;


namespace GUILayer
{
    public partial class GUISearch : Form
    {
        private MovieController movieCtr;
        private ShowController showCtr;

        public GUISearch()
        {
            InitializeComponent();
            string[] categories = {"Skuespiller", "Titel", "Beskrivelse", "Instruktør", "Kategori", "Sprog", "Aktiv"};
            comboBoxSearchCategory.Items.AddRange(categories);
            movieCtr = new MovieController();
            showCtr = new ShowController();
        }

        //Interaktion between GUI-Forms
        private void buttonSearchBooking_Click(object sender, EventArgs e)
        {
            Form newForm = new GUITicketBooking();
            this.Hide();
            newForm.ShowDialog();
            this.Close();         
        }

        private void buttonSearchBack_Click(object sender, EventArgs e)
        {
            Form newForm = new GUIStart();
            this.Hide();
            newForm.ShowDialog();
            this.Close(); 
        }

        //Find method
        private void buttonSearchFind_Click(object sender, EventArgs e)
        {
            //input is a keyword and a category
            string input = textSearchInput.Text.Trim();
            string category = comboBoxSearchCategory.Text.Trim();
            
            //create a list with found movies
            List<Movie> movies = movieCtr.FindMovies(input, category);
            listBoxSearchTitle.Items.AddRange(movies.ToArray());
        }

        //select a movie to display further information
        private void listBoxSearchTitle_SelectedIndexChanged(object sender, EventArgs e)
        {
            Movie selection = (Movie) listBoxSearchTitle.SelectedItem;
            ClearFields();
            textSearchDescription.Text = selection.Description;
            textBoxSearchActor.Text = selection.Actor;
            textBoxSearchAge.Text = "" + selection.MinAge;
            textBoxSearchLanguage.Text = selection.Language;
            List<Show> selectionShows = showCtr.FindShowsByMovie(selection);
            foreach(Show show in selectionShows)
            {
                string showString = "Sal " + show.Room.Name + ": " + show.DateTime.ToString() + " " + show.Movie.Title + " - " + show.ShowPrice;
                listSearchDate.Items.Add(showString);
            }
            

            //listSearchDate.Items.AddRange(.ToArray());
        }

        private void ClearFields()
        {
            textSearchDescription.Clear();
            textBoxSearchActor.Clear();
            textBoxSearchAge.Clear();
            textBoxSearchLanguage.Clear();
            listSearchDate.Items.Clear();
        }
    }
}
